<?php
class Add_user extends CI_Controller{
     
     public function __construct(){
        parent::__construct();       
       
        $this->load->model('user_model');
    }
    public function index(){
        
        $cond['user_category_deleted']=0;
        $data['user_category']=$this->user_model->get_user_category($cond)->result();   
             
        $this->nav_link('Add user');        
        $this->template->write_view('content','add_user',$data);
        $this->template->render();
    }
    
    public function create(){
         $this->form_validation->set_rules(array(
          array('field' => 'user_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email'),
          array('field' => 'user_password', 'label' => 'Password', 'rules' => 'trim|required')
         ));
         if ($this->form_validation->run($this)==FALSE)
        {
            $this->nav_link('Add user');
            $this->template->write_view('content','add_user','');
            $this->template->render();
        }else{
             $input_data['user_email']=$this->input->post('user_email')  ;
            $input_data['user_password']=md5($this->input->post('user_password') ) ;
            $input_data['user_name']=$this->input->post('user_name')  ;
            $input_data['user_address']=$this->input->post('user_address')  ; 
            $input_data['user_category_id']=$this->input->post('user_category_id')  ;
            $input_data['organisation_name']=$this->input->post('organisation_name')  ;                        
            $input_data['user_phone']=$this->input->post('user_phone')  ;            
            $this->user_model->add_user($input_data);
            $this->list_user();
             
        }
    }
    
    public function list_user(){
         if($this->session->userdata('user_id')>0){
             $cond['user_deleted']=0;
            $data['users_list']=$this->user_model->get_users($cond)->result();
            $nav['navigation']=array('home');
            
            $this->nav_link('List User');
            $this->template->write_view('content','list_user',$data);
            $this->template->render();
        }
    }
     
    public function nav_link($va){
        $data['navigation']= $va; 
        $this->template->write_view('navigation','navigation',$data);
    }
} 
?>